package fhp.hlhj.giantfold.activity.malls

import android.annotation.SuppressLint
import android.webkit.WebViewClient
import android.widget.Toast
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.interfaces.IGoodsDetail
import fhp.hlhj.giantfold.javaBean.ErroBean
import fhp.hlhj.giantfold.javaBean.GoodsDetailBean
import fhp.hlhj.giantfold.presenter.GoodsDetailPresenter
import fhp.hlhj.giantfold.utils.LogUtil
import kotlinx.android.synthetic.main.activity_goods_detail_aty.*

class GoodsDetailAty : BaseActivity() , IGoodsDetail {
    override fun getContentId(): Int = R.layout.activity_goods_detail_aty
    private lateinit var goodsDetailPresenter:GoodsDetailPresenter
    @SuppressLint("SetJavaScriptEnabled")
    override fun initView() {
        /**
         * 初始化WebView
         */
        val settings = webView.settings
        settings.javaScriptEnabled=true
        webView.webViewClient=object : WebViewClient(){}
        /**
         * 获取参数
         */
        goodsDetailPresenter=GoodsDetailPresenter(this)
        val goodId = intent.getStringExtra("goodId")
        val params=HttpParams()
        LogUtil.log("商品ID"+goodId+intent.extras.toString())
        params.put("token",Contents.taokeToken)
//        params.put("id",goodId)
        goodsDetailPresenter.getGood(params,goodId)
    }

    override fun onError(erro: ErroBean) {
    }

    override fun getGoodsDetail(goodsDetailBean: GoodsDetailBean) {
        if (goodsDetailBean.proInfo!=null){
            webView.loadUrl(goodsDetailBean.proInfo.couponLink)
        }else{
            Toast.makeText(this,"商品已下架",Toast.LENGTH_SHORT).show()
        }
    }

    override fun showLoading() {
        LogUtil.log("开始请求商品详情拉")
    }

}
